<?php
require_once '../inc/configuration.php';
require_once '../inc/connexion_db.php';
require_once '../inc/fonctions_sql.php';

$message_action = "";

$action = isset($_POST["action"]) ? $action = $_POST["action"] : "";

if($action==1) {
    
    $tab_name_form = array(
        "id_contact",
        "rdv_date",
        "heure",
        "type_rdv",
        "objet",
        "observations"
    );
    
    $message_action = ajouter_donnees("rendez_vous", $tab_name_form);
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="ISO-8859-1">
        <title>CARNET D'ADRESSES - RENDEZ-VOUS > AJOUTER</title>
        
        <?php require_once "../inc/css_js_bootstrap/css_js_bootstrap.php"; ?>
        
        <style>
            .table {
                width: 500px;
            }
            
            th {
                width: 35%;
                text-align: right;
            }
            textarea.form-control {
                /*background-color: #ccc;*/
                height: 150px;
            }
            
        </style>
    </head>
    
    <body>
        
        <?php require_once '../inc/menus/menu_principal.php'; ?>
        
        <h1>AJOUTER UN RENDEZ-VOUS</h1>
        <?php if(!empty($message_action)) { ?>
            <div id="message_action" class="alert <?php echo $message_action["css_class"]; ?>"><?php echo $message_action["texte"]; ?></div>
        <?php } ?>
        <form name="form_ajouter" id="form_ajouter" method="post" enctype="multipart/form-data">
        <div>
            <table class="table table-bordered">
                <tr>
                    <th>Contact</th>
                    <td>
                        <?php 
                        //REQUETE SQL
                        $sql_ent = "SELECT id, raison_sociale FROM entreprises ORDER BY raison_sociale ASC";
                        $req_ent = mysqli_query($connexion_bd, $sql_ent);                        
                        ?>
                        <select name="id_contact" id="id_contact" class="form-control">
                            <?php
                                while($data_ent = mysqli_fetch_assoc($req_ent)) {
                                $sql_contacts = "SELECT id, nom, prenom FROM contacts WHERE id_entreprise = ".$data_ent["id"];
                                $req_contacts = mysqli_query($connexion_bd, $sql_contacts);
                                while($data_contacts = mysqli_fetch_assoc($req_contacts)) {
                            ?>
                                    <option value="<?php echo $data_contacts["id"]; ?>"><?php echo $data_contacts["nom"]; ?> <?php echo $data_contacts["prenom"]; ?> => <?php echo $data_ent["raison_sociale"]; ?></option>
                                    <?php
                                    }
                                }
                                    ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>Date</th>
                    <td><input type="text" name="rdv_date" id="rdv_date" class="form-control"></td>
                </tr>
                <tr>
                    <th>Heure</th>
                    <td><input type="text" name="heure" id="heure" class="form-control"></td>
                </tr>
                <tr>
                    <th>Type</th>
                    <td><input type="text" name="type_rdv" id="type_rdv" class="form-control"></td>
                </tr>
                <tr>
                    <th>Objet</th>
                    <td><input type="tect" name="objet" id="objet" class="form-control"></td>
                </tr>
                <tr>
                    <th>Observations</th>
                    <td><textarea name="observations" id="observations" class="form-control"></textarea></td>
                </tr>
                <tr>
                    <th></th>
                    <td><button type="submit" name="action" class="btn btn-success" value="1"><span class="glyphicon glyphicon-ok"></span> Ajouter</button></td>
                </tr>
            </table>
        </div>
        </form>
    </body>
</html>
